﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.Practices.Unity;
using Skynet.WebAdministracion.Views.ExamsDynMgm;
using Skynet.BusinessEntities;
namespace Skynet.WebSite.Administracion
{
    public partial class ExamDynMgmView : Infrastructure.Web.Views.Page,  IExamsDynMgmView
    {

        
        private ExamsDynMgmPresenter _Presenter;
        [Dependency]
        public ExamsDynMgmPresenter Presenter
        {
            get { return _Presenter; }
            set { _Presenter= value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

            string res = this.Request.Form["btnOk"];
            generate(count);
            if (!this.IsPostBack)
                this.Presenter.OnViewInitialized();
            this.Presenter.OnViewLoaded();
            
        }

        private int count = 0;
        protected void Page_PreInit(object sender, EventArgs e)
        {

            var ini = Request.Form["ctl00$MainContent$TextBox1"];
            
            if (!string.IsNullOrWhiteSpace(ini))
            {
                count = int.Parse(ini);
                
            }
            //MetadataHandlerRegistration d;
            ///BuddyMetadataProvider a;
        }
        protected void Page_Init(object sender, EventArgs e)
        {            
            this.odsExams.ObjectCreating+= delegate(object ocds, ObjectDataSourceEventArgs args) { args.ObjectInstance = this.Presenter; };
            this.GridView1.EnableDynamicData(typeof(Skynet.WebAdministracion.Model.WEExam));
        }

        public void generate(int input)
        {
            
            for (int i = 0; i < input; i++)
            {

                var btn = new Button() { Text = "Click" };
                btn.ID = "btn" + i.ToString();
                btn.Click += new EventHandler(btn_Click);
                this.Panel1.Controls.Add(btn);
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
   


            


        }

        void btn_Click(object sender, EventArgs e)
        {
            var btn = sender as Button;
            Response.Write(btn.ID); 
        }
    }
}